﻿using System;
using System.Windows;
using System.Windows.Controls;
namespace PSE.Deployment.ConfigurationManager.Controls
{
	public class ClickedEventArgs : EventArgs
	{
		bool _isChecked;
		public bool IsChecked
		{
			get { return _isChecked; }
			set { _isChecked = value; }
		}

		public ClickedEventArgs(bool isChecked)
		{
			_isChecked = isChecked;
		}
	}

	public class StartStopButton : Button
	{
		public event ClickedEventHandler Clicked;
		public delegate void ClickedEventHandler(StartStopButton sender, ClickedEventArgs args);

		public bool IsChecked
		{
			get { return (bool)GetValue(IsCheckedProperty); }
			set { SetValue(IsCheckedProperty, value); }
		}

		public bool IsProcessing
		{
			get { return (bool)GetValue(IsProcessingProperty); }
			set { SetValue(IsProcessingProperty, value); }
		}

		public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(StartStopButton), new FrameworkPropertyMetadata(false));
		public static readonly DependencyProperty IsProcessingProperty = DependencyProperty.Register("IsProcessing", typeof(bool), typeof(StartStopButton), new FrameworkPropertyMetadata(false));

		public StartStopButton()
		{
			this.SetResourceReference(StartStopButton.StyleProperty, "ButtonActive");
			this.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
			this.VerticalAlignment = System.Windows.VerticalAlignment.Top;

			this.Click += new System.Windows.RoutedEventHandler(Button_Click);
		}

		void Button_Click(object sender, System.Windows.RoutedEventArgs e)
		{
			if (Clicked != null)
				Clicked(this, new ClickedEventArgs(this.IsChecked));
		}
	}
}